package com.stylefeng.guns.modular.platform.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.page.PageInfoBT;
import com.stylefeng.guns.core.redis.RedisService;

import org.springframework.web.bind.annotation.RequestParam;

import com.stylefeng.guns.modular.platform.dao.SmallInfoMapper;
import com.stylefeng.guns.modular.platform.model.BuyerDemand;
import com.stylefeng.guns.modular.platform.model.SmallInfo;
import com.stylefeng.guns.modular.platform.service.ISmallInfoService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-07-24 17:04:18
 */
@Controller
@RequestMapping("smallInfo")
public class SmallInfoController extends BaseController {

	private String PREFIX = "/platform/smallInfo/";

	@Autowired
	private ISmallInfoService smallInfoService;

	@Autowired
	private SmallInfoMapper smallInfoMapper;
	


	/**
	 * 跳转到首页
	 */
	@RequestMapping("")
	public String index() {
		return PREFIX + "smallInfo.html";
	}

	/**
	 * 跳转到添加
	 */
	@RequestMapping("/smallInfo_add")
	public String smallInfoAdd() {
		return PREFIX + "smallInfo_add.html";
	}

	/**
	 * 跳转到修改
	 */
	@RequestMapping("/smallInfo_update/{smallInfoId}")
	public String smallInfoUpdate(@PathVariable Integer smallInfoId, Model model) {
		SmallInfo smallInfo = smallInfoService.selectById(smallInfoId);
		model.addAttribute("item", smallInfo);
		LogObjectHolder.me().set(smallInfo);
		return PREFIX + "smallInfo_edit.html";
	}

	/**
	 * 获取列表
	 */
	@RequestMapping(value = "/list")
	@ResponseBody
	public Object list(SmallInfo smallInfo) {
		Page<SmallInfo> page = new PageFactory<SmallInfo>().defaultPage();
		List<SmallInfo> lsit;
		try {
			lsit = smallInfoMapper.getListInfo(page, smallInfo);
			page.setRecords(lsit);
		} catch (Exception e) {
			e.printStackTrace();
		}
		PageInfoBT<SmallInfo> d = super.packForBT(page);
		return d;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/add")
	@ResponseBody
	public Object add(SmallInfo smallInfo) { 
		smallInfo.setUpdateTime(new Date());
		smallInfo.setScrapyTime(new Date());
		smallInfo.setStatus(0);
		smallInfoService.insert(smallInfo);
		return SUCCESS_TIP;
	}

	/**
	 * 删除
	 */
	@RequestMapping(value = "/delete")
	@ResponseBody
	public Object delete(@RequestParam Integer smallInfoId) {
		smallInfoService.deleteById(smallInfoId);
		return SUCCESS_TIP;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/update")
	@ResponseBody
	public Object update(SmallInfo smallInfo) {
		smallInfoService.updateById(smallInfo);
		return SUCCESS_TIP;
	}

	/**
	 * 详情
	 */
	@RequestMapping(value = "/detail/{smallInfoId}")
	@ResponseBody
	public Object detail(@PathVariable("smallInfoId") Integer smallInfoId) {
		return smallInfoService.selectById(smallInfoId);
	}

	/**
	 * 获取列表
	 */
	@RequestMapping(value = "/getList", method = RequestMethod.GET)
	@ResponseBody
	public Object getList(Page page, SmallInfo smallInfo) {
		return smallInfoService.getList(page, smallInfo);
	}

	/**
	 * 获取列表
	 */
	@RequestMapping(value = "/getRandomList", method = RequestMethod.GET)
	@ResponseBody
	public Object getRandomList() {
		return smallInfoService.getRandomList();
	}

	/**
	 * 获取热门列表
	 */
	@RequestMapping(value = "/getHotList", method = RequestMethod.GET)
	@ResponseBody
	public Object getHotList() {
		return smallInfoService.getHotList();
	}

	/**
	 * 获取最新列表
	 */
	@RequestMapping(value = "/getNewList", method = RequestMethod.GET)
	@ResponseBody
	public Object getNewList() {
		return smallInfoService.getNewList();
	}

	/**
	 * 获取最新列表
	 */
	@RequestMapping(value = "/getTypeList", method = RequestMethod.GET)
	@ResponseBody
	public Object getTypeList() {
		return smallInfoService.getTypeList();
	}

}
